package pl.nazaweb.samplesandtutorials.abstracts.contentproviders;

import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	private List<AbstractTable> tables;
	
	public DatabaseHelper(Context context, String databaseName,
			List<AbstractTable> tableList, int databaseVersion) {
		super(context, databaseName,  null, databaseVersion);
		tables = tableList;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		for(AbstractTable table : tables){
			db.execSQL(table.getCreateQuery());
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		for(AbstractTable table : tables){
			db.execSQL(table.getDropQuery());
		}
		onCreate(db);
	}
}
